package com.ysjy.course.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.wkbb.common.handler.JsonUtil;
import com.wkbb.common.utils.StringUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@ApiModel("课程包")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class YsCoursePackage implements Serializable {

    @ApiModelProperty("ID")
    private Long id;
    @ApiModelProperty("唯一标识")
    private String uniqueId;
    @NotBlank(message = "参数缺失")
    @ApiModelProperty("课程包名称")
    private String title;
    @NotBlank(message = "参数缺失")
    @ApiModelProperty("封面")
    private String logo;
    @NotBlank(message = "参数缺失")
    @ApiModelProperty("简介")
    private String introduce;
    @NotBlank(message = "参数缺失")
    @ApiModelProperty("详情")
    private String content;
    @NotNull(message = "参数缺失")
    @ApiModelProperty("总金额(分)")
    private Integer amount;
    @ApiModelProperty("开启购买须知")
    private Boolean openPurchaseNotes;
    @ApiModelProperty("购买须知")
    private String purchaseNotes;

    @NotBlank(message = "参数缺失")
    @ApiModelProperty("上架机构（学校）id列表（多个,逗号隔开）")
    private String orgIds;
    @NotBlank(message = "参数缺失")
    @ApiModelProperty("上架机构（学校）名称列表")
    private String orgNames;

    @ApiModelProperty("课程包课程uniqueId列表（多个,逗号隔开）")
    private String courseUniqueIds;
    @ApiModelProperty("课程包托管uniqueId列表（多个,逗号隔开）")
    private String trusteeshipUniqueIds;

    @ApiModelProperty("课程包课程列表")
    private List<OrgCourse> courses;
    @ApiModelProperty("课程包托管列表")
    private List<YsTrusteeship> trusteeships;

    @NotNull(message = "参数缺失")
    @ApiModelProperty("报名开始时间")
    private Date signUpStartTime;

    @NotNull(message = "参数缺失")
    @ApiModelProperty("报名结束时间")
    private Date signUpEndTime;
    @ApiModelProperty("报名状态 0未开始、1报名中、2已结束、3已报名")
    private Integer signUpStatus;

    @ApiModelProperty("上架状态：0未上架 1上架")
    private Integer shelvesStatus;
    @ApiModelProperty("是否已经购买：0未购买 1已购买")
    private Integer buyStatus;
    @ApiModelProperty("上架时间")
    private Date shelvesTime;
    @ApiModelProperty("更新时间")
    private Date updateTime;
    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("课程数量")
    public Integer getCourseCount() {
        int count = 0;
        if (!StringUtil.isEmpty(courseUniqueIds)) count += courseUniqueIds.split(",").length;
        if (!StringUtil.isEmpty(trusteeshipUniqueIds)) count += trusteeshipUniqueIds.split(",").length;
        return count;
    }

    public void initSignUpStatus() {
        if (signUpStatus != null || signUpStartTime == null || signUpEndTime == null) return;
        Date currDate = new Date();
        if (currDate.getTime() > signUpEndTime.getTime()) {
            signUpStatus = 2;
            return;
        }
        if (currDate.getTime() > signUpStartTime.getTime()) {
            signUpStatus = 1;
            return;
        }
        signUpStatus = 0;
    }

    public static void main(String[] args) {
        YsCoursePackage data = new YsCoursePackage();
        data.setTitle("暑期托管1");
        data.setLogo("https://qiniu.childrenonline.cn/Fin5cd36X2FCZOPEaNhU0qZCpq-x");
        data.setOrgIds("1452");
        data.setOrgNames("紫城中学");
        data.setContent("服务内容服务内容服务内容");
        data.setIntroduce("简介简介");
        data.setOpenPurchaseNotes(true);
        data.setPurchaseNotes("购买须知");
        data.setCourseUniqueIds("2022072814060623,2022071515543922");
        data.setTrusteeshipUniqueIds("2022072810565160");
        data.setAmount(1);
        System.out.println(JsonUtil.objectToJson(data));


    }
}
